function quickSort(arr) {
  if (arr.length <= 1) return arr
  let middle = Math.floor(arr.length / 2)
  let middleValue = arr.splice(middle, 1)[0]
  let leftArr = [], rightArr = []
  for (let i = 0; i < arr.length; i++) {
    arr[i] < middleValue ? leftArr.push(arr[i]) : rightArr.push(arr[i])
  }
  return quickSort(leftArr).concat(middleValue, quickSort(rightArr))
}
let arr = []
for (let i = 0; i<10; i++){
  arr.push(Math.floor(Math.random() * 40))
}
console.log(arr)
console.log(quickSort(arr))
